import { notFound } from 'next/navigation'
import { getRequestConfig } from 'next-intl/server'

import { routing } from './routing'

type Locale = (typeof routing.locales)[number]

interface Messages {
  [key: string]: string
}

export default getRequestConfig(async ({ locale }) => {
  if (!routing.locales.includes(locale as Locale)) notFound()

  const messages = (await import(`@/messages/${locale}.json`)) as {
    default: Messages
  }

  return {
    messages: messages.default,
  }
})
